//
//  WHlocalLifeViewController.m
//  WHstoreItemProtect
//
//  Created by wztx on 2017/11/4.
//  Copyright © 2017年 sdwh.com. All rights reserved.
//

#import "WHlocalLifeViewController.h"

#import "UIColor+Addition.h"

#import "SDCycleScrollView.h"
#import "HYBNetworking.h"
#import "YYModel.h"


#import "WHmainModel.h"
#import "WHhomePictureModel.h"


@interface WHlocalLifeViewController ()<SDCycleScrollViewDelegate>

//轮播视图
@property(nonatomic, strong) SDCycleScrollView *sdcycleScrollerView;

@end

@implementation WHlocalLifeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupNavgationBar];
    [self setupUI];
    [self loadSlideshow];
    
    
}

#pragma mark - 导航栏的设置
- (void)setupNavgationBar {
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithHex:0xFF6800];
    
    
}
#pragma MARK - UI
- (void)setupUI
{
    //顶部轮播视图
    UIView *topV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 138)];
    ((UITableView *)self.view).tableHeaderView = topV;
    
    // 网络加载 --- 创建不带标题的图片轮播器
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0,self.view.bounds.size.width ,138) delegate:self placeholderImage:[UIImage imageNamed:@""]];
    self.sdcycleScrollerView = cycleScrollView;
    cycleScrollView.delegate = self;
    cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolAlimentRight;
    cycleScrollView.currentPageDotColor = [UIColor colorWithHex:0xFF6800];
    [topV addSubview:cycleScrollView];
    cycleScrollView.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    cycleScrollView.autoScrollTimeInterval = 3.0;
    
}
#pragma MARK - 轮播图
- (void)loadSlideshow
{
    __weak __typeof(self)weakSelf = self;
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[@"type"] = @"2";
    //轮播
    [HYBNetworking postWithUrl:@"index.php/Home/Banner/bannerlist" refreshCache:YES params:dic success:^(id response) {
        WHmainModel *mainModel = [WHmainModel yy_modelWithJSON:response];
        if (mainModel.status == 1) {
            NSMutableArray *picArrM = [NSMutableArray array];
            for (WHhomePictureModel *picModel in [NSArray yy_modelArrayWithClass:[WHhomePictureModel class] json:mainModel.data]) {
                [picArrM addObject:picModel.pic];
            }
            weakSelf.sdcycleScrollerView.imageURLStringsGroup = picArrM;
        }
        NSLog(@"%@", response);
    } fail:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}
#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", (long)index);
}

#

@end
